﻿using System;

namespace Net.Formats.oEmbed
{
    /// <summary>
    /// Responses of this type must obey the maxwidth and maxheight 
    /// request parameters.
    /// </summary>
    public class PhotoResponse : GenericResponse
    {
        #region Class Constructor

        public PhotoResponse( ) : base( ResponseType.Photo ) { }

        #endregion

        #region Private Fields

        Uri url;
        int? width;
        int? height;

        #endregion

        #region Public Properties

        /// <summary>
        /// The source URL of the image. Consumers should be able to insert this 
        /// URL into an <img> element. Only HTTP and HTTPS URLs are valid.
        /// </summary>
        public Uri Url
        {
            get
            {
                if ( url == null )
                    throw new ArgumentNullException( "Url", "Url property is a required property" );
                return url;
            }
            set
            {
                if ( value != null && ( value.Scheme != "http" && value.Scheme != "https" ) )
                    throw new ArgumentException( "Only HTTP and HTTPS urls are valid", "Url" );


                if ( url != value )
                    url = value;
            }
        }

        /// <summary>
        /// The width in pixels of the image 
        /// specified in the url parameter.
        /// </summary>
        public int? Width
        {
            get
            {
                if ( !width.HasValue )
                    throw new ArgumentNullException( "Width", "Width is a required property" );
                return width;
            }
            set
            {
                if ( width != value )
                    width = value;
            }
        }

        /// <summary>
        /// The height in pixels of the image 
        /// specified in the url parameter.
        /// </summary>
        public int? Height
        {
            get
            {
                if ( height == null )
                    throw new ArgumentNullException( "Height", "Height is a required property" );
                return height;
            }
            set
            {
                if ( height != value )
                    height = value;
            }
        }

        #endregion
    }
}
